//
//  JQMineProfileHeadCell.m
//  JQLive
//
//  Created by Bruce on 2020/8/18.
//  Copyright © 2020 mlkq. All rights reserved.
//

#import "JQMineProfileHeadCell.h"
#import "UIView+Extension.h"

@interface  JQMineProfileHeadCell()
@property (nonatomic, strong) UIImageView *cellHeadImageView;
@property (nonatomic, strong) UILabel *cellLb;

@end

@implementation JQMineProfileHeadCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)initView{
    UIView *cellBackgroundV = [[UIView alloc] init];//WithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, 48)];
    [self.contentView addSubview:cellBackgroundV];
    MY_WEAK;
    [cellBackgroundV mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.left.mas_equalTo(strongSelf.mas_left).offset(10);
        make.right.mas_equalTo(strongSelf.mas_right).offset(-10);
        make.top.bottom.equalTo(strongSelf);
    }];
    cellBackgroundV.backgroundColor = [UIColor whiteColor];
//    self.backgroundColor = kColorWithHex(0xF2F4FC);
    self.cellBackgroundV = cellBackgroundV;
    
    
    UILabel *cellLb = [[UILabel alloc] init];
    [cellBackgroundV addSubview:cellLb];
    self.cellLb = cellLb;
    [cellLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(cellBackgroundV.mas_left).offset(18);
        make.centerY.equalTo(cellBackgroundV);
    }];
    cellLb.textColor = MYColor3;
    cellLb.font = [UIFont systemFontOfSize:14];
    cellLb.text = @"头像";
    
    UIImageView *cellHeadImageView = [[UIImageView alloc] init];
    [cellBackgroundV addSubview:cellHeadImageView];
    self.cellHeadImageView = cellHeadImageView;
    cellHeadImageView.backgroundColor = [UIColor whiteColor];
    [cellHeadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(cellBackgroundV.mas_right).offset(-18);
        make.centerY.equalTo(cellBackgroundV);
        make.size.mas_equalTo(CGSizeMake(80, 80));
    }];
    cellHeadImageView.image = [UIImage svgImageNamed:@"mine_headIcon" size:CGSizeMake(80, 80)];
    
    [cellHeadImageView layoutIfNeeded];
    [cellHeadImageView round:40 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerBottomRight];
    
    UIView *circle = [[UIView alloc] init];
    //    circle.backgroundColor = [UIColor lightGrayColor];
    [cellHeadImageView addSubview:circle];
    [circle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(cellHeadImageView);
    }];
    
    CGFloat width = 40;
    CGFloat height = 40;
    //创建背景圆环
    CAShapeLayer *trackLayer = [CAShapeLayer layer];
    trackLayer.frame = circle.bounds;
    //清空填充色
    trackLayer.fillColor = [UIColor clearColor].CGColor;
    //设置画笔颜色 即圆环背景色
    //    trackLayer.strokeColor =  kColorWithHex(0xFFE9BE).CGColor;// [UIColor colorWithRed:170/255.0 green:210/255.0 blue:254/255.0 alpha:1].CGColor;
    trackLayer.lineWidth = 4;
    //设置画笔路径
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(width, height) radius:width startAngle:- M_PI_2 endAngle:-M_PI_2 + M_PI * 2 clockwise:YES];
    //path 决定layer将被渲染成何种形状
    trackLayer.path = path.CGPath;
    [circle.layer addSublayer:trackLayer];
    
    CALayer *gradientLayer = [CALayer layer];
    gradientLayer.frame = CGRectMake(0, 0, 80, 80);//circle.bounds;
    
    CAGradientLayer *gradientLayer1 = [CAGradientLayer layer];
    gradientLayer1.frame = CGRectMake(0, 0, 80, 80);//circle.bounds;//CGRectMake(width/2.0, 0, width/2.0,  height/2.0);
    gradientLayer1.colors = @[(__bridge id)kColorWithHex(0xFFE9BE).CGColor, (__bridge id)kColorWithHex(0xED9C4E).CGColor];
    //startPoint和endPoint属性，他们决定了渐变的方向。这两个参数是以单位坐标系进行的定义，所以左上角坐标是{0, 0}，右下角坐标是{1, 1}
    //startPoint和pointEnd 分别指定颜色变换的起始位置和结束位置.
    //当开始和结束的点的x值相同时, 颜色渐变的方向为纵向变化
    //当开始和结束的点的y值相同时, 颜色渐变的方向为横向变化
    //其余的 颜色沿着对角线方向变化
    gradientLayer1.startPoint = CGPointMake(0, 0);//CGPointMake(0.2, 0);
    gradientLayer1.endPoint = CGPointMake(1, 1);//CGPointMake(0.8, 1);
    [gradientLayer addSublayer:gradientLayer1];
    
    [circle.layer addSublayer:gradientLayer];
    
    CAShapeLayer *progressLayer = [CAShapeLayer layer];
    progressLayer.frame = circle.bounds;
    progressLayer.fillColor = [UIColor clearColor].CGColor;
    progressLayer.strokeColor = [UIColor colorWithRed:170/255.0 green:210/255.0 blue:254/255.0 alpha:1].CGColor;
    progressLayer.lineWidth = 4;
    progressLayer.path = path.CGPath;
    gradientLayer.mask = progressLayer;
    
    [circle layoutIfNeeded];
    
    [circle round:40 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerBottomRight];
}

- (void)setCellImage:(UIImage *)image{
    self.cellHeadImageView.image = image;
//    self.cellLb.text = cellLbStr;
}


@end
